{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                    <!--<div class="layui-input-inline" style="margin-top: 5px">-->
                    <!--<input type="text"  name="start" onfocus="wk.lay_date(this);" class="layui-input layer-date search" placeholder="开始时间"/>-->
                    <!--</div>-->

                    <!--<div class="layui-input-inline" style="margin-top: 5px">-->
                    <!--<input type="text"  name="end" onfocus="wk.lay_date(this);" class="layui-input layer-date search" placeholder="结束时间"/>-->
                    <!--</div>-->

                    <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                    <input type="text" id="keyword" class="layui-input search" name="keyword" value="" placeholder="标题"/>
                    </div>
                    <!--<div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">-->
                    <!--<select name="province" lay-search="" id="province"  lay-filter="province">-->
                    <!--<option value="">全部</option>-->
                    <!--<option value="1" >上架中</option>-->
                    <!--<option value="2" >已下架</option>-->
                    <!--</select>-->
                    <!--</div>-->
                    <div class="layui-input-inline" style="margin-top: 5px">
                    <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                    <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                    </div>
                    </div>
                </div>

                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('add')}');">
                            <i class="fa fa-plus"></i> 添加
                        </button>
                    </div>
                </div>

            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>


                    <!--状态显示模板-->
                    <script type="text/html" id="video_img">
                        <img src="{{d.video_img}}" class="table-img layui-cricle" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>
                    <script type="text/html" id="staBar">
                        <input type="checkbox" value="{{d.video_id}}"  lay-skin="switch"  lay-text="可以下载|不可以下载" lay-filter="OnOff"{{ d.is_down == 1 ? 'checked' : '' }}  >
                    </script>
                    <script type="text/html" id="is_vip">
                        <input type="checkbox" value="{{d.video_id}}"  lay-skin="switch"  lay-text="Vip|普通" lay-filter="OnOff1"{{ d.is_vip == 2 ? 'checked' : '' }}  >
                    </script>
                    <script type="text/html" id="is_index">
                        <input type="checkbox" value="{{d.video_id}}"  lay-skin="switch"  lay-text="指定首页|不指定首页" lay-filter="OnOff2"{{ d.is_index == 1 ? 'checked' : '' }}  >
                    </script>
                    <script type="text/html" id="is_type">
                        <input type="checkbox" value="{{d.video_id}}"  lay-skin="switch"  lay-text="上架|下架" lay-filter="OnOff3"{{ d.is_type == 1 ? 'checked' : '' }}  >
                    </script>
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('update')}?id={{d.video_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑">编辑</a>
                        {{# if(d.is_vip == 2){ }}
                            {{# if(d.video_jrjx == 1){ }}
                            <a href="javascript:;" onclick="wk.confirm('{{d.video_id}}','{:url('down1')}','不指定到今日精选吗?')" class="btn btn-danger  btn-xs m-r-xs" title="不指定">不指定今日精选</a>
                            {{# } }}

                            {{# if(d.video_jrjx == 2){ }}
                            <a href="javascript:;" onclick="wk.confirm('{{d.video_id}}','{:url('up1')}','确定指定到今日精选吗?')" class="btn btn-primary  btn-xs m-r-xs" title="指定今日精选">指定今日精选</a>
                            {{# } }}
                        {{# } }}
                        <!--<a href="javascript:;" onclick="wk.confirm('{{d.person_id}}','{:url('del')}','确定删除吗?')" class="btn btn-primary btn-xs m-r-xs" title="删除">删除</a>-->
                        <a href="javascript:;" onclick="wk.href('{:url('index1')}?id={{d.video_id}}')" class="btn btn-primary btn-xs m-r-xs" title="视频列表">视频列表</a>
                        <!--{{# if(d.is_vip == 2){ }}-->
                            <!--{{# if(d.is_exclusive == 2){ }}-->
                            <!--<a href="javascript:;" onclick="wk.confirm('{{d.video_id}}','{:url('up3')}','确认推荐到Vip专属吗?')" class="btn btn-primary  btn-xs m-r-xs" title="推荐到Vip专属">推荐到Vip专属</a>-->
                            <!--{{# } }}-->
                            <!--{{# if(d.is_exclusive == 1){ }}-->
                            <!--<a href="javascript:;" onclick="wk.confirm('{{d.video_id}}','{:url('down3')}','不推荐到Vip专属吗?')" class="btn btn-danger  btn-xs m-r-xs" title="不推荐到Vip专属">不推荐到Vip专属</a>-->
                            <!--{{# } }}-->
                        <!--{{# } }}-->
                        <a href="javascript:;" onclick="wk.confirm('{{d.video_id}}','{:url('del')}','确定删除?')" class="btn btn-danger  btn-xs m-r-xs" title="删除">删除</a>

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("video/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: 100
//            ,toolbar: '#toolbarDemo'
//            ,defaultToolbar: ['filter', 'exports']
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type:'numbers', width: 80, title: '序号'}
//                , {field: 'banner_id', width: 80, title: 'ID', align: 'center'}
                {field: 'video_id', width: 50, title: 'ID', align: 'center'}
                , {field: 'video_name', width: 100, title: '名称', align: 'center'}
                , {field: 'video_img', width: 100, title: '封面图片', align: 'center',templet:"#video_img"}
                , {field: 'person_name', width: 200, title: '所属名家', align: 'center'}
                , {field: 'video_num', width: 100, title: '播放数量', align: 'center'}
                , {field: 'is_down_name', width: 150, title: '是否下载', align: 'center', templet: '#staBar'}
                , {field: 'is_vip_name', width: 100, title: '是否VIP', align: 'center',templet: '#is_vip'}
                , {field: 'is_index_name', width: 150, title: '是否指定首页', align: 'center',templet:"#is_index"}
                , {field: 'is_type_name', width: 150, title: '上下架', align: 'center',templet:"#is_type"}
                , {field: 'video_type_name', width: 150, title: '所属分类', align: 'center'}
                , {field: 'video_modular_name', width: 100, title: '所属模块', align: 'center'}
                , {field: 'hot_keyword', width: 100, title: '流派', align: 'center'}
                , {field: 'video_time', width: 220, title: '添加时间', align: 'center'}
                , {field: 'video_year', width: 150, title: '年份', align: 'center'}
                , {field: 'video_jrjx_name', width: 150, title: '是否今日精选', align: 'center'}
                , {fixed: 'right', width:300, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.layui-cricle').viewer();//图片查看器
            }
        });
        //监听单元格编辑
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            var patrn = /^[0-9]*$/;
            if(!patrn.test(value)){
                layer.msg('排序值只能为数字',{icon:2,time:1500,shade: 0.1},function(){
                    //重载当前页表格
                    $(".layui-laypage-btn").click();
                });
                return false;
            }
            wk.changeSort(data.banner_id,"{:url('sort')}",field,value);
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("isDown")}',obj);
        });
        //监听状态开关操作
        form.on('switch(OnOff1)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("isVip")}',obj);
        });
        //监听状态开关操作
        form.on('switch(OnOff2)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("isIndex")}',obj);
        });
        //监听状态开关操作
        form.on('switch(OnOff3)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("isType")}',obj);
        });
        //批量操作
        var $ = layui.$, active = {
            //批量删除
            batchDel:function () {
                wk.batchDel(getIds(),"{:url('del')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['s_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>